#include "BaseType.h"
#include "Tracer.h"

using namespace libemb;
/**
 * 桥接模式：
 * 1.将一个类拆分成抽象部分和实现部分
 * 2.抽象层是桥，它将类的多维度结合在一起。
 * 适用场景：
 * 1.类具有多个维度，且会在多个维度上发生变化。
 * 2.增加变化维度,只需要修改抽象部分，不需要修改其子类。
 **/

//棋子颜色
class ChessColor{
DECL_CLASSNAME(ChessColor)
public:
};

class BlackColor:public ChessColor{
DECL_CLASSNAME(BlackColor)
public:
};

class WhiteColor:public ChessColor{
DECL_CLASSNAME(WhiteColor)
public:
};

//棋子形状
class ChessShape{
DECL_CLASSNAME(ChessShape)
public:
};

class CircleShape:public ChessShape{
DECL_CLASSNAME(CircleShape)
public:
};

class SquareShape:public ChessShape{
DECL_CLASSNAME(SquareShape)
public:
};

//抽象类：将类的多维度变化桥接在一起
class Chess{
DECL_CLASSNAME(Chess)
public:
    void setColor(std::shared_ptr<ChessColor> color)
    {
        m_color = color;
    }
    void setShape(std::shared_ptr<ChessShape> shape)
    {
        m_shape = shape;
    }
    virtual void draw()
    {
        TRACE_DBG_CLASS("paint a %s with color:%s and shape:%s",className(),m_color->className(),m_shape->className());
    }
protected:
    std::shared_ptr<ChessColor> m_color;
    std::shared_ptr<ChessShape> m_shape;
};

//实现类
class ChineseChess:public Chess{
DECL_CLASSNAME(ChineseChess)
public:
};

int main()
{
    Tracer::getInstance().setLevel(TRACE_LEVEL_DBG);
	Tracer::getInstance().addSink(std::make_shared<STDSink>()).start();

    auto black = std::make_shared<BlackColor>();
    auto circle = std::make_shared<CircleShape>();
    auto chess = std::make_shared<Chess>();
    chess->setColor(black);
    chess->setShape(circle);
    chess->draw();
    
    auto white = std::make_shared<WhiteColor>();
    auto square = std::make_shared<SquareShape>();
    chess = std::make_shared<ChineseChess>();
    chess->setColor(white);
    chess->setShape(square);
    chess->draw();
    return RC_OK;
}